package com.zhb.lkd.controller;


import com.zhb.lkd.base.PageResponse;
import com.zhb.lkd.base.ResponseResult;
import com.zhb.lkd.pojos.dto.SkuClassPageDto;
import com.zhb.lkd.pojos.entity.SkuClass;
import com.zhb.lkd.service.ISkuClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 商品类别表 前端控制器
 * </p>
 *
 * @author haibin
 * @since 2024-08-18
 */
@RestController
@RequestMapping("/api/vm-service/skuClass")
@Slf4j
@Api(tags = "商品类别相关接口")
public class SkuClassController {

    @Resource
    private ISkuClassService skuClassService;

    @GetMapping("/search")
    @ApiOperation("分类搜索")
    public ResponseResult login(SkuClassPageDto skuClassPageDto) {
        log.info("分类搜索{}", skuClassPageDto);
        PageResponse pageResponse = skuClassService.search(skuClassPageDto);
        return ResponseResult.ok(pageResponse);
    }

    @PostMapping("")
    @ApiOperation("新增分类")
    public ResponseResult create(@RequestBody SkuClass skuClass) {
        log.info("新增分类{}", skuClass);
        skuClassService.create(skuClass);
        return ResponseResult.ok();
    }
    @GetMapping("/{id}")
    @ApiOperation("获取分类基本信息")
    public ResponseResult findById(@PathVariable String id) {
        log.info("获取分类基本信息{}", id);
      SkuClass skuClass=  skuClassService.findById(id);
        return ResponseResult.ok(skuClass);
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除分类")
    public ResponseResult deleteById(@PathVariable String id) {
        log.info("删除分类{}", id);
         skuClassService.deleteById(id);
        return ResponseResult.ok();
    }

    @PutMapping()
    @ApiOperation("修改分类")
    public ResponseResult updateById(@RequestBody SkuClass skuClass) {
        log.info("修改分类{}", skuClass);
        boolean b = skuClassService.updateById(skuClass);
        return ResponseResult.ok();
    }
}